package com.edu.policy.data.http;

import okhttp3.*;
import java.io.IOException;

public class OkHttpUtil {

    private final OkHttpClient client;

    public OkHttpUtil() {
        client = new OkHttpClient();
    }

    public String get(String url) throws IOException {
        Request request = new Request.Builder().url(url).build();
        try (Response response = client.newCall(request).execute()) {
            return response.body() != null ? response.body().string() : null;
        }
    }

    public String post(String url, String json) throws IOException {
        RequestBody body = RequestBody.create(json, MediaType.parse("application/json; charset=utf-8"));
        Request request = new Request.Builder().url(url).post(body).build();
        try (Response response = client.newCall(request).execute()) {
            return response.body() != null ? response.body().string() : null;
        }
    }
}

